﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using MethodIT.Helper;
using MyGeneration.dOOdads;

using Hr20.DAL;
using Hr20.BLL;
using Hr20.ProcessFlow;

namespace Appraisal.Web.Admin
{
    public partial class NewBidder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int ID = HelperURL.GetIntFromUrlString("ID");
                if (ID != -1)
                {
                    Bind(ID);
                }
            }
        }

        private void Bind(int ID)
        {
            ZB_Bidder b = new ZB_Bidder();
            if (b.LoadByPrimaryKey(ID))
            {
                txtName.Text = b.Name;
                chkEnable.Checked = b.Enable.Equals("Y");

                txtFullName.Text = b.FullName ;
                txtCEO.Text = b.CEO;
                txtMan.Text = b.Man;
                txtPhone.Text = b.Phone;
                txtFax.Text = b.Fax;
                txtPose.Text = b.Pose;
                txtAddress.Text = b.Address;
                txtEmail.Text = b.Email;
                txtWebURL.Text = b.WebURL;
                txtMoney.Text = b.CorpMoney;
                txtAddress2.Text = b.CorpAddress;
                txtCode.Text = b.CorpCode;
                txtBank.Text = b.CorpBank;
                txtBankCode.Text = b.CorpNumber;
                txtLevel.Text = b.CorpLevel;
                txtReMark.Text = b.Remark;
                txtDesc.Text = b.CorpGroup;
            }
        }

        private void Save()
        {
            int ID = HelperURL.GetIntFromUrlString("ID");
            ZB_Bidder b = new ZB_Bidder();
            b.Where.Name.Value = txtName.Text;
            b.Where.ID.Value = ID;
            b.Where.ID.Operator = WhereParameter.Operand.NotEqual;
            //检查名称是否重复
            if (b.Query.Load())
            {
                HelperMessage.Message("公司名称重复!");
                return;
            }

            //保存
            if (!b.LoadByPrimaryKey(ID))
            {

                b.AddNew();
                b.ID = SequenceGenerator.GetNextVal("Bidder");
            }
            b.Name = txtName.Text;
            b.Enable = chkEnable.Checked ? "Y" : "N";
            b.FullName = txtFullName.Text;
            b.CEO = txtCEO.Text;
            b.Man = txtMan.Text ;
            b.Phone = txtPhone.Text ;
            b.Fax= txtFax.Text ;
            b.Pose = txtPose.Text;
            b.Address = txtAddress.Text ;
            b.Email = txtEmail.Text ;
            b.WebURL = txtWebURL.Text;
            b.CorpMoney= txtMoney.Text ;
            b.CorpAddress= txtAddress2.Text ;
            b.CorpCode= txtCode.Text ;
            b.CorpBank = txtBank.Text ;
            b.CorpNumber = txtBankCode.Text ;
            b.CorpLevel = txtLevel.Text ;
            b.Remark = txtReMark.Text ;
            b.CorpGroup = txtDesc.Text;

            b.Save();
            HelperURL.Redirect("BidderAdmin.aspx");
        }

        protected void lbSave_Click(object sender, EventArgs e)
        {
            Save();
        }

        protected void lbSaveBottom_Click(object sender, EventArgs e)
        {
            Save();
        }
    }
}
